import { getXieYiYiYuan } from '/@/stores/baseInfo';

let _loginInfo = ref({} as LoginInfo);
// const _loginInfo = reactive({} as AppInfo);

export const loginInfo = computed(() => {
	return _loginInfo.value;
});

// 获取登录界面的缓存, 必须在初始组织机构后调用
export function setUserInfo(userInfo: any) {
	_loginInfo.value.tenantId = userInfo.tenantId;
	_loginInfo.value.userId = userInfo.id;
	_loginInfo.value.realName = userInfo.realName;

	// 如果登录的是协议医院, 把院区设置设置成协议医院
	if (userInfo.tenantId != 1300000000001) {
		let obj = getXieYiYiYuan(userInfo.tenantId);
		_loginInfo.value.yuanQuId = obj.id;
		_loginInfo.value.yuanQuName = obj.name;
	}
}

// 从存储获取登录界面字段
export function getLoginInfoFromStore() {
	_loginInfo.value = JSON.parse(localStorage.getItem('loginInfo') ?? '{}') as LoginInfo;
	return _loginInfo.value;
}

// 存储登录信息
export function saveLoginInfo(loginInfo: any) {
	localStorage.setItem('loginInfo', JSON.stringify(loginInfo)); //再次登录用
	_loginInfo.value = loginInfo; //登录后使用
}

// 是否临床
export const isLinChuang = computed(() => {
	return loginInfo.value.zhanDian == '医生站' || loginInfo.value.zhanDian == '护士站'
})